function [llmax,amax,t0]=accelerate3(v0)
l=10;
amax=0;

function aa=getaa(ll)
t01=1e-2;
t02=1;
[aa1,tt1]=magnet3(v0,l,ll,t01);
[aa2,tt2]=magnet3(v0,l,ll,t02);
sign1=sign(1/2*t01-tt1);
sign2=sign(1/2*t02-tt2);
while (t02-t01>0.01)
    t0=(t01+t02)/2;
    [aa,tt]=magnet3(v0,l,ll,t0);
    sign3=sign(1/2*t0-tt);
    if (sign3==sign2)
        t02=t0;
    else
        if(sign3==sign1)
            t01=t0;
        else
            fprintf('error while finding root');
        end;
    end;
end;
end

for ll=3:-0.1:0.1
        aa=getaa(ll);
        if (amax<aa)
            amax=aa;
            llmax=ll;
        end;
end;
end
